/**********************************************************************
* <pre>
* FILE : ServiceActivityManageSummary.java
* CLASS : ServiceActivityManageSummary
*
* AUTHOR : PGM
*
* FUNCTION :服务活动管理---服务活动计划分析
*
*
*======================================================================
* CHANGE HISTORY LOG
*----------------------------------------------------------------------
* MOD. NO.| DATE     | NAME | REASON | CHANGE REQ.
*----------------------------------------------------------------------
*         |2010-06-13| PGM  | Created |
* DESCRIPTION:
* </pre>
***********************************************************************/
/**
 * $Id: ServiceActivityManageSummary.java,v 1.1 2010/08/16 01:44:11 yuch Exp $
 */
package com.infodms.dms.actions.claim.serviceActivity;
import java.util.Date;
import java.util.Map;

import org.apache.log4j.Logger;
import com.infodms.dms.bean.AclUserBean;
import com.infodms.dms.bean.TtAsActivityBean;
import com.infodms.dms.common.Constant;
import com.infodms.dms.common.ErrorCodeConstant;
import com.infodms.dms.common.getCompanyId.GetOemcompanyId;
import com.infodms.dms.dao.claim.serviceActivity.ServiceActivityManageSummaryDao;
import com.infodms.dms.exception.BizException;
import com.infodms.dms.po.TtAsActivityDealerPO;
import com.infodms.dms.po.TtAsActivityEvaluatePO;
import com.infodms.dms.util.sequenceUitl.SequenceManager;
import com.infoservice.mvc.context.ActionContext;
import com.infoservice.mvc.context.RequestWrapper;
import com.infoservice.po3.bean.PageResult;
/**
 * Function       :  服务活动管理---服务活动评估
 * @author        :  PGM
 * CreateDate     :  2010-06-13
 * @version       :  0.1
 */
public class ServiceActivityManageSummary {
	private Logger logger = Logger.getLogger(ServiceActivityManageSummary.class);
	private ServiceActivityManageSummaryDao dao = ServiceActivityManageSummaryDao.getInstance();
	private ActionContext act = ActionContext.getContext();//获取ActionContext
	private AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
	private final String ServiceActivityInitUrl = "/jsp/claim/serviceActivity/serviceActivityManageSummary.jsp";//查询页面
	private final String ServiceActivityOptionUrl = "/jsp/claim/serviceActivity/serviceActivityManageSummaryOption.jsp";//编辑页面
	/**
	 * Function       :  服务活动管理---服务活动评估页面初始化
	 * @param         :  
	 * @return        :  serviceActivityManageSummaryInit
	 * @throws        :  Exception
	 * LastUpdate     :  2010-06-13
	 */
	public void serviceActivityManageSummaryInit(){
		try {
			act.setForword(ServiceActivityInitUrl);
		} catch (Exception e) {
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"服务活动管理---服务活动评估页面初始化");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	/**
	 * Function       :  根据条件查询服务活动管理---服务活动评估中符合条件的信息
	 * @param         :  request-活动编号、活动开始日期、活动结束日期
	 * @return        :  服务活动管理
	 * @throws        :  Exception
	 * LastUpdate     :  2010-06-13
	 */
	public void serviceActivityManageSummaryQuery(){
		try {
			RequestWrapper request = act.getRequest();
			String activityCode = request.getParamValue("activityCode");    //活动编号
			String startdate = request.getParamValue("startdate");          //活动开始日期
			String enddate = request.getParamValue("enddate");              //活动结束日期
			Long companyId=GetOemcompanyId.getOemCompanyId(logonUser);      //公司ID
			TtAsActivityBean ActivityBean = new TtAsActivityBean();
			ActivityBean.setActivityCode(activityCode);
			ActivityBean.setStartdate(startdate);
			ActivityBean.setEnddate(enddate);
			ActivityBean.setDealerId(logonUser.getDealerId());
			ActivityBean.setCompanyId(String.valueOf(companyId));
			Integer curPage = request.getParamValue("curPage") !=null ? Integer.parseInt(request.getParamValue("curPage")) : 1;
			PageResult<Map<String, Object>> ps = dao.getServiceActivityManageSummaryQuery(ActivityBean,curPage,Constant.PAGE_SIZE );
			act.setOutData("ps", ps);
			act.setForword(ServiceActivityInitUrl);
		}catch (Exception e) {
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"服务活动管理---服务活动评估");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	/**
	 * Function         : 服务活动管理---服务活动评估[编辑]查询方法：状态为：[已经下发]的活动
	 * @param           : request-活动ID
	 * @return          : 满足条件的服务活动管理信息
	 * @throws          : Exception
	 * LastUpdate       : 2010-06-13
	 */
	public void	serviceActivitySummaryQuery(){
		try {
			RequestWrapper request = act.getRequest();
			String activityId = request.getParamValue("activityId");    //活动ID
			String dealerId = logonUser.getDealerId();//经销商ID
			TtAsActivityEvaluatePO evaluatePO=dao.serviceActivitySummaryQuery(activityId,dealerId);//调用服务活动评估[编辑]查询方法
			request.setAttribute("evaluatePO", evaluatePO);
			request.setAttribute("activityId", activityId);
			request.setAttribute("dealerId", dealerId);
			act.setForword(ServiceActivityOptionUrl);//跳转到服务活动评估[编辑]页面
		}catch (Exception e) {
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"服务活动管理---服务活动评估[编辑]查询");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	/**
	 * Function         : 服务活动管理---服务活动评估总结上报
	 * @param           : request-活动ID、老带新信息留存数、老带新成交数、活动效果自我评价、建议及改进措施
	 * @return          : 满足条件的服务活动管理信息
	 * @throws          : Exception
	 * LastUpdate       : 2010-06-13
	 */
	public void serviceActivitySummaryOption(){
		try {
		RequestWrapper request = act.getRequest();
		String dealerId=  request.getParamValue("dealerId");            //经销商ID
		String activityId = request.getParamValue("activityId");        //活动ID
		String inAmount = request.getParamValue("inAmount");            //进厂台次
		String inGuarantee = request.getParamValue("inGuarantee");      //三包内数量
		String outGuarantee = request.getParamValue("outGuarantee");    //三包外数量
		String repairAmount = request.getParamValue("repairAmount");    //维修数量
		String maintainAmount = request.getParamValue("maintainAmount"); //保养数量
		String onAmount = request.getParamValue("onAmount");            //老带新信息留存数
		String onCamount = request.getParamValue("onCamount");          //老带新成交数
		String evaluate = request.getParamValue("evaluate");            //活动效果自我评价
		String measures = request.getParamValue("measures");            //建议及改进措施
		
		TtAsActivityEvaluatePO evaluatePOContent =new TtAsActivityEvaluatePO();
		evaluatePOContent.setId(Long.parseLong(SequenceManager.getSequence("")));
		evaluatePOContent.setDealerId(Long.parseLong(dealerId));
		if(!"".equals(activityId)&&null!=activityId){
			evaluatePOContent.setActivityId(Long.parseLong(activityId)); 
		}
		if(!"".equals(inAmount)&&null!=inAmount){
			evaluatePOContent.setInAmount(Integer.parseInt(inAmount)); 
		}
		if(!"".equals(inGuarantee)&&null!=inGuarantee){
			evaluatePOContent.setInGuarantee(Integer.parseInt(inGuarantee)); 
		}
		if(!"".equals(outGuarantee)&&null!=outGuarantee){
			evaluatePOContent.setOutGuarantee(Integer.parseInt(outGuarantee)); 
		}
		if(!"".equals(repairAmount)&&null!=repairAmount){
			evaluatePOContent.setRepairAmount(Integer.parseInt(repairAmount)); 
		}
		if(!"".equals(maintainAmount)&&null!=maintainAmount){
			evaluatePOContent.setMaintainAmount(Integer.parseInt(maintainAmount)); 
		}
		if(!"".equals(onAmount)&&null!=onAmount){
			evaluatePOContent.setOnAmount(Integer.parseInt(onAmount)); 
		}
		if(!"".equals(onCamount)&&null!=onCamount){
			evaluatePOContent.setOnCamount(Integer.parseInt(onCamount));
		}
		evaluatePOContent.setEvaluate(evaluate);
		evaluatePOContent.setMeasures(measures);
		evaluatePOContent.setUpdateBy(logonUser.getUserId());
		evaluatePOContent.setUpdateDate(new Date());
		dao.serviceActivitySummaryOption(evaluatePOContent);//服务活动评估总结上报
		
		TtAsActivityDealerPO DealerPO =new TtAsActivityDealerPO();//条件
		DealerPO.setActivityId(Long.parseLong(activityId));
		TtAsActivityDealerPO DealerPOCon =new TtAsActivityDealerPO();//内容
		DealerPOCon.setStatus(Constant.SUMMARY_STATUS_01);//服务活动评估状态:已评估
		dao.serviceActivitySummaryOptionStatus(DealerPO, DealerPOCon);
		act.setForword(ServiceActivityInitUrl);
		}catch (Exception e) {
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"服务活动管理---服务活动评估总结上报");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
}